package com.ruoyi.project.jiaqin.cooperatemsg.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.cooperatemsg.domain.CooperateMsg;
import com.ruoyi.project.jiaqin.cooperatemsg.service.ICooperateMsgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 合作留言Controller
 * 
 * @author admin
 * @date 2021-02-02
 */
@Controller
@RequestMapping("/jiaqin/cooperatemsg")
public class CooperateMsgController extends BaseController
{
    private String prefix = "jiaqin/cooperatemsg";

    @Autowired
    private ICooperateMsgService cooperateMsgService;

    @RequiresPermissions("jiaqin:cooperatemsg:view")
    @GetMapping()
    public String cooperatemsg()
    {
        return prefix + "/cooperatemsg";
    }

    /**
     * 查询合作留言列表
     */
    @RequiresPermissions("jiaqin:cooperatemsg:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CooperateMsg cooperateMsg)
    {
        startPage();
        List<CooperateMsg> list = cooperateMsgService.selectCooperateMsgList(cooperateMsg);
        return getDataTable(list);
    }

    /**
     * 导出合作留言列表
     */
    @RequiresPermissions("jiaqin:cooperatemsg:export")
    @Log(title = "合作留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CooperateMsg cooperateMsg)
    {
        List<CooperateMsg> list = cooperateMsgService.selectCooperateMsgList(cooperateMsg);
        ExcelUtil<CooperateMsg> util = new ExcelUtil<CooperateMsg>(CooperateMsg.class);
        return util.exportExcel(list, "cooperatemsg");
    }

    /**
     * 新增合作留言
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合作留言
     */
    @RequiresPermissions("jiaqin:cooperatemsg:add")
    @Log(title = "合作留言", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CooperateMsg cooperateMsg)
    {
        return toAjax(cooperateMsgService.insertCooperateMsg(cooperateMsg));
    }

    /**
     * 修改合作留言
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CooperateMsg cooperateMsg = cooperateMsgService.selectCooperateMsgById(id);
        mmap.put("cooperateMsg", cooperateMsg);
        return prefix + "/edit";
    }

    /**
     * 修改保存合作留言
     */
    @RequiresPermissions("jiaqin:cooperatemsg:edit")
    @Log(title = "合作留言", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CooperateMsg cooperateMsg)
    {
        return toAjax(cooperateMsgService.updateCooperateMsg(cooperateMsg));
    }

    /**
     * 删除合作留言
     */
    @RequiresPermissions("jiaqin:cooperatemsg:remove")
    @Log(title = "合作留言", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cooperateMsgService.deleteCooperateMsgByIds(ids));
    }
}
